//
//  SingleNetService.m
//  Shengzhuli
//
//  Created by 卡忙科技 on 16/8/11.
//  Copyright © 2016年 kamangkeji. All rights reserved.
//

#import "SingleNetService.h"
#import "GFXNetworkHandle.h"
#import "NormalShopGoodsModel.h"
#import "BuyCarModel.h"
#import "PaySingleModel.h"

NSString * const MailGoodsLists = @"product/normal/list";//商城列表
NSString * const NormalShopSearchUrl = @"shop/product/normal/search";//商城搜索"
NSString * const NormalShopGoodsDetailUrl = @"auth/product/normal/productDetail";//商品详情
NSString * const AddFocusUrl = @"auth/keep/product";//关注
NSString * const AddCarUrl = @"auth/shop/car/add";//添加购物车
NSString * const BuyCarList = @"auth/shop/car/list";//购物车列表
NSString * const BuyCarUpdateList = @"auth/shop/car/update/count";//购物车加减
NSString * const BuyCarDelete = @"auth/shop/car/delete";//购物车加减
NSString * const BuyCarToPay = @"auth/go/shopList";//购物车结算
NSString * const CreateSingle = @"auth/order/buy/create";//创建订单

NSString * const CommentLists = @"list/commet/by/productNo";//评论列表
NSString * const ShopProductList = @"shop/product/normal/list";//店铺产品列表
NSString * const ShopTroduction = @"shop/get/info/by/shop/id";//店铺简介

@implementation SingleNetService

+ (void)getMailGoodsListsWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,NSArray *gooods))response
{
    [[GFXNetworkHandle shareHandle]post:MailGoodsLists params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            NSMutableArray *sources = [NSMutableArray array];
            for (NSDictionary *dict in json[@"result"]) {
                NormalShopGoodsModel *model = [NormalShopGoodsModel objectWithDict:dict];
                [sources addObject:model];
            }
            response(YES,json[@"message"],sources);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}

+ (void)normalShopSearchWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,NSArray *gooods))response
{
    [[GFXNetworkHandle shareHandle]post:NormalShopSearchUrl params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            NSMutableArray *sources = [NSMutableArray array];
            for (NSDictionary *dict in json[@"result"]) {
                NormalShopGoodsModel *model = [NormalShopGoodsModel objectWithDict:dict];
                [sources addObject:model];
            }
            response(YES,json[@"message"],sources);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}

+ (void)normalShopGoodsDetailParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,NSString *errorCode,AddGoodsModel *gooodsModel))response
{
    [[GFXNetworkHandle shareHandle]post:NormalShopGoodsDetailUrl params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            AddGoodsModel *gooodsModel = [AddGoodsModel objectWithDict:json[@"result"]];
            response(YES,json[@"message"],json[@"status"],gooodsModel);
        }else{
            response(NO,json[@"message"],json[@"status"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil,nil);
    }];
}

+ (void)addFocusParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg))response
{
    [[GFXNetworkHandle shareHandle]post:AddFocusUrl params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            response(YES,json[@"message"]);
        }else{
            response(NO,json[@"message"]);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError);
    }];
}

+ (void)addBuyCarParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg))response
{
    [[GFXNetworkHandle shareHandle]post:AddCarUrl params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            response(YES,json[@"message"]);
        }else{
            response(NO,json[@"message"]);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError);
    }];
}

+ (void)buyCarListParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,NSArray *buyCarGoods))response
{
    [[GFXNetworkHandle shareHandle]post:BuyCarList params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            NSMutableArray *goods = [NSMutableArray array];
            for (NSDictionary *dict in json[@"result"]) {
                BuyCarModel *model = [BuyCarModel objectWithDict:dict];
                [goods addObject:model];
            }
            response(YES,json[@"message"],goods);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}

+ (void)buyCarUpdateParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg))response
{
    [[GFXNetworkHandle shareHandle]post:BuyCarUpdateList params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            response(YES,json[@"message"]);
        }else{
            response(NO,json[@"message"]);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError);
    }];
}

+ (void)buyCarDeleteParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg))response
{
    [[GFXNetworkHandle shareHandle]post:BuyCarDelete params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            response(YES,json[@"message"]);
        }else{
            response(NO,json[@"message"]);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError);
    }];
}

+ (void)buyCarToPayParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,NSArray *payModels))response
{
    [[GFXNetworkHandle shareHandle]post:BuyCarToPay params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            NSMutableArray *pays = [NSMutableArray array];
            for (NSDictionary *dict in json[@"result"]) {
                BuyCarModel *model = [BuyCarModel objectWithDict:dict];
                [pays addObject:model];
            }
            response(YES,json[@"message"],pays);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}

+ (void)createSingleParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,SingleCreateModel *model))response
{
    [[GFXNetworkHandle shareHandle]post:CreateSingle params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            SingleCreateModel *model = [SingleCreateModel objectWithDict:json[@"result"]];
            response(YES,json[@"message"],model);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}

+ (void)shopProductListWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,NSArray *gooods))response
{
    [[GFXNetworkHandle shareHandle]post:ShopProductList params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            NSMutableArray *sources = [NSMutableArray array];
            for (NSDictionary *dict in json[@"result"]) {
                NormalShopGoodsModel *model = [NormalShopGoodsModel objectWithDict:dict];
                [sources addObject:model];
            }
            response(YES,json[@"message"],sources);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}

+ (void)ShopTroductionWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,ShopModel *model))response
{
    [[GFXNetworkHandle shareHandle]post:ShopTroduction params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            ShopModel *model = [ShopModel objectWithDict:json[@"result"]];
            response(YES,json[@"message"],model);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}

+ (void)getCommentsWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,NSArray *lists))response
{
    [[GFXNetworkHandle shareHandle]post:CommentLists params:parames success:^(id json) {
        NSLog(@"评论---%@",json);
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            NSMutableArray *comments = [NSMutableArray array];
            for (NSDictionary *commitDict in json[@"result"]) {
                CommentModel *model = [CommentModel objectWithDict:commitDict];
                [comments addObject:model];
            }
            response(YES,json[@"message"],comments);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}

@end
